package org.egrit;

import java.awt.Point;

/**
 * A grid that returns a uniform constant value for all positions within 
 * its bounds. This is slightly more efficient than using a {@linkplain CalculatedGrid}
 * with a constant function.
 *
 * @author michael
 */
public class ConstantGrid extends AbstractGrid {
    private final Number constantValue;

    public ConstantGrid(int width, int height, Number constantValue, Number outsideValue) {
        this(GridBoundsFactory.create(0, width - 1, 0, height - 1), constantValue, outsideValue);
    }
    
    public ConstantGrid(IGridBounds bounds, Number constantValue, Number outsideValue) {
        super(bounds, outsideValue);
        this.constantValue = constantValue;
    }
    
    @Override
    public Number getGridValue(int gridX, int gridY) {
        if (isWithin(gridX, gridY)) {
            return constantValue;
        }
        
        return outsideValue;
    }

    @Override
    public Number getGridValue(Point gridPos) {
        return getGridValue(gridPos.x, gridPos.y);
    }

}
